<?php

/**
 * This is the model class for table "underground_tank".
 *
 * The followings are the available columns in table 'underground_tank':
 * @property integer $id
 * @property string $name_of_contractor_or_installer
 * @property string $date_installed
 * @property integer $no
 * @property string $kind_of_flammable
 * @property integer $capacity
 * @property string $dept_of_land_fill
 * @property string $distance_between_tank
 * @property integer $inspection_id
 *
 * The followings are the available model relations:
 * @property Inspection $inspection
 */
class UndergroundTank extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return UndergroundTank the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'underground_tank';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('inspection_id', 'required'),
			array('no, capacity, inspection_id', 'numerical', 'integerOnly'=>true),
			array('distance_between_tank', 'length', 'max'=>45),
			array('name_of_contractor_or_installer, date_installed, kind_of_flammable, dept_of_land_fill', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name_of_contractor_or_installer, date_installed, no, kind_of_flammable, capacity, dept_of_land_fill, distance_between_tank, inspection_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'inspection' => array(self::BELONGS_TO, 'Inspection', 'inspection_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name_of_contractor_or_installer' => 'Name Of Contractor Or Installer',
			'date_installed' => 'Date Installed',
			'no' => 'No',
			'kind_of_flammable' => 'Kind Of Flammable',
			'capacity' => 'Capacity',
			'dept_of_land_fill' => 'Dept Of Land Fill',
			'distance_between_tank' => 'Distance Between Tank',
			'inspection_id' => 'Inspection',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name_of_contractor_or_installer',$this->name_of_contractor_or_installer,true);
		$criteria->compare('date_installed',$this->date_installed,true);
		$criteria->compare('no',$this->no);
		$criteria->compare('kind_of_flammable',$this->kind_of_flammable,true);
		$criteria->compare('capacity',$this->capacity);
		$criteria->compare('dept_of_land_fill',$this->dept_of_land_fill,true);
		$criteria->compare('distance_between_tank',$this->distance_between_tank,true);
		$criteria->compare('inspection_id',$this->inspection_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}